package com.ibeeking.found.common.config.feign.fallback;

import com.ibeeking.found.common.config.feign.MsgFeignClient;
import com.ibeeking.found.common.entity.msg.MsgSimpleParam;
import com.ibeeking.found.common.entity.msg.MsgTemplateParam;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class MsgFeignClientFallbackFactory implements FallbackFactory<MsgFeignClient> {
    @Override
    public MsgFeignClient create(Throwable throwable) {
        return new MsgFeignClient() {

            @Override
            public ResponseResult<Boolean> sendSimpleMessage(MsgSimpleParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，发送内容消息失败。", true);
            }

            @Override
            public ResponseResult<Boolean> sendTemplateMessage(MsgTemplateParam param) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，发送模板消息失败。", true);
            }

            @Override
            public ResponseResult<String> queryVerificationCode(String key, String mobile) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询验证码失败。", "");
            }

            @Override
            public ResponseResult<Boolean> clearVerificationCode(String key, String mobile) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，清除验证码失败。", true);
            }

            @Override
            public ResponseResult<Boolean> checkVerificationCode(String key, String mobile, String code) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，校验验证码失败。", true);
            }
        };
    }
}
